package ms.jung.andorid.caldavtodo.account;

import java.util.ArrayList;

import ms.jung.andorid.caldavtodo.R;
import ms.jung.andorid.caldavtodo.R.id;
import ms.jung.andorid.caldavtodo.R.layout;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


/*
 * A Custom Adapter and Class for the Spinner Element
 * 
 * @author Felix Martens <cheefy13@gmail.com>
 * 
 */

public class AccountAdapter extends ArrayAdapter<Account> {


	private ArrayList<Account> objects;

	public AccountAdapter(Context context, int textViewResourceId, ArrayList<Account> objects) {
		super(context, textViewResourceId,objects);
		this.objects = objects;
	}


	public View getView(int position, View convertView, ViewGroup parent){

		View view = convertView;

		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.rowaccount, null);
		}
		
		Account i = objects.get(position);

		if (i != null) {

					 
			      
				TextView t = (TextView) view.findViewById(R.id.listname);
					if (t != null){
						t.setText(i.getName()+" ("+String.valueOf(i.getCount())+")");
					
					}
			      	
			      	t = (TextView) view.findViewById(R.id.listtype);
			      	if (t != null){
			      		t.setText(i.getType());
			      	
			      	}
			   
			      	
			    
			

		}
	      	
			return view;
	}
	public View getDropDownView(int position, View convertView, ViewGroup parent){

		View view = convertView;

		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.rowdropdown, null);
		}
		
		Account i = objects.get(position);

		if (i != null) {

					 
			      
			      	TextView t = (TextView) view.findViewById(R.id.listname);
			      	if (t != null){
			      		t.setText(i.getName()+" ("+String.valueOf(i.getCount())+")");
			      		
			      		Log.d("Name",i.getName());
			      	}
			      	
			      	t = (TextView) view.findViewById(R.id.listtype);
			      	if (t != null){
			      		t.setText(i.getType());
			      		
			      		Log.d("Type",i.getType());
			      	}
			      	
			     
			

		}
	      	
			return view;
	}
	

    public int getCount(){
       return objects.size();
    }

    public Account getItem(int position){
       return objects.get(position);
    }

    public long getItemId(int position){
       return position;
    }

}

